package com.tee.rocketmqstudy.demo;

import com.tee.rocketmqstudy.constant.MqConstant;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.junit.Test;

/**
 * @author tee
 * @date 2025/9/9
 */
public class BAsyncTest {

    @Test
    public void asyncProduce() throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("async-producer-group");
        producer.setNamesrvAddr(MqConstant.NAME_SRV_ADDR);
        producer.start();
        Message message = new Message("asyncTopic", "异步消息".getBytes());
        producer.send(message, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("异步回调成功");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("异步回调失败" + throwable.getMessage());
            }
        });
        System.out.println("主线程执行");
        System.in.read();
    }
}
